/*
 * TestDumpCCStatement.c
 *
 *  Created on: 2012/05/31
 *      Author: guanxiaoying
 */
#include "TestDump.h"
typedef struct {
	PSZ key;
}TYPE_PROPERTY_KEY;


static VOID dumpStatement( AST astStmt ){
	AST astCodeScp = CStatement.getCodeScope( astStmt );
	sprintf( tempBuf, header_format, dumpGetStr(XML_RECORD), astStmt );
	dumpOutputStream( tempBuf );

	dumpCodeScopeAsField( astCodeScp );

	if( CStatement.isBlock( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "block" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_UNITECHAIN),
			"parameter",
			CStatement.block_getChain( astStmt ));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_UNITECHAIN));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isBreak( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "break" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.break_getLoopOrSwitch( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isCase( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "case" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter",
			CStatement.case_getConstExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter-next",
			CStatement.case_getNextCase( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.case_getStatement( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter-switch",
			CStatement.case_getSwitch( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isContinue( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "continue" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );


		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.continue_getLoop( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isDefault( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "default" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.default_getStatement( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter-switch",
			CStatement.default_getSwitch( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isDo( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "do" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.do_getBody( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter",
			CStatement.do_getCondExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isExpression( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "expression" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter",
			CStatement.expStatement_getExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isFor( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "for" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		if( CStatement.for_getInitExp( astStmt ) ){
			sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
				"parameter-initial",
				CStatement.for_getInitExp( astStmt ));
			dumpOutputStream( tempBuf );
			sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
			dumpOutputStream( tempBuf );
		}
		if( CStatement.for_getInit_Decl( astStmt ) ){
			sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_DECLARATION),
				"parameter-initial",
				CStatement.for_getInit_Decl( astStmt ));
			dumpOutputStream( tempBuf );
			sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_DECLARATION));
			dumpOutputStream( tempBuf );
		}
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter-condition",
			CStatement.for_getCondExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter-counter",
			CStatement.for_getIncExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.for_getBody( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isGoto( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "goto" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_SYMBOL),
			"parameter",
			CStatement.goto_getLabelInfo( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_SYMBOL));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.goto_getLabelStatement( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isIf( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "if" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter",
			CStatement.if_getCondExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.if_getBody( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter-else",
			CStatement.if_getElseBody( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isLabel( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "label" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_SYMBOL),
			"parameter",
			CStatement.label_getLabelInfo( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_SYMBOL));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_UNITECHAIN),
			"parameter",
			CStatement.label_getGotoChain( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_UNITECHAIN));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.label_getStatement( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isReturn( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "return" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter",
			CStatement.return_getExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isSwitch( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "switch" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter",
			CStatement.switch_getCondExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter-body",
			CStatement.switch_getBody( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter-case",
			CStatement.switch_getFirstCase( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter-default",
			CStatement.switch_getDefault( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if(  CStatement.isWhile( astStmt ) ){
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( "while" );
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parameter",
			CStatement.while_getCondExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );

		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parameter",
			CStatement.while_getBody( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else{
		sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND),
			"");
		dumpOutputStream( tempBuf );
		dumpParameterStr ( dumpGetStr( XML_ERROR ));
		sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND));
		dumpOutputStream( tempBuf );
	}
	if(  CStatement.isParentExp( astStmt ) ){
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_EXPRESSION),
			"parent",
			CStatement.parent_GetExp( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_EXPRESSION));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isParentStmt( astStmt ) ){
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_STATEMENT),
			"parent",
			CStatement.parent_GetStmt( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_STATEMENT));
		dumpOutputStream( tempBuf );
	}else if( CStatement.isParentSymbol( astStmt ) ){
		sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_SYMBOL),
			"parent",
			CStatement.parent_GetSymbol( astStmt ));
		dumpOutputStream( tempBuf );
		sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_SYMBOL));
		dumpOutputStream( tempBuf );
	}
	sprintf( tempBuf, tail_format, dumpGetStr(XML_RECORD) );
	dumpOutputStream( tempBuf );
}
VOID DumpStatement ( PSZ szPath, PSZ postfix ){
	AST astStmt;
	AST astMax;

	if( szPath == NULL ){
		return;
	}
	strcpy( file_buf, szPath );
	file_buf[strlen(szPath)] = '\0';
	strcat(file_buf, postfix );
	file_buf[strlen(szPath)+strlen(postfix)] = '\0';
	if( COEXIT_SUCCESS == dumpOutputStreamInit_file(file_buf)){
		astStmt = MIN_ARRAY;
		astMax = CStatement.getMax();
		sprintf( tempBuf, top_header, dumpGetStr(XML_STATEMENT) );
		dumpOutputStream( tempBuf );
		while( astStmt <= astMax ){
			dumpStatement( astStmt );
			astStmt ++;
		}
		sprintf( tempBuf, top_end, dumpGetStr(XML_STATEMENT) );
		dumpOutputStream( tempBuf );
		dumpOutputStreamEnd_file();
	}
}
